Speed up GameObjectManager::get_singleton_by_type #2986
Closed
+5
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This mitigates a major cause of lag for me -- calls to
Sector::get_camera()
were very slow on levels with many objects, because each call ended up scanning through the full list of objects.Sector::get_camera()
gets called a lot, by everyBadGuy::is_offscreen()
and many times inParticleSystem::draw()
. The fix is to look up the singleton objects using (ultimately) them_objects_by_type_index
map.(SuperTux still has a bunch of other performance issues of this type;
GameObjectManager::get_object_count
andGameObjectManager::get_objects_by_type
are other functions that are called too often and will search the full object list instead of usingm_objects_by_type_index
or an equivalent. Long term, I'd also recommend replacingm_objects_by_type_index
with a vector indexed by an integer type ids.)